<?php

/**
* AuthForm.class.php
*
* Concrete page module responsable for creating slide show list
*
* @author     Blazej Zieba <b@zieba.info>
* @copyright  2007 konekto.com
* @version    CVS: $Id:$
*/
require_once("Auth/Auth.php");
require_once("framework/config.php");
require_once("framework/PageModule.class.php");
require_once("HTML/QuickForm.php");
require_once("HTML/QuickForm/Renderer/Default.php");
require_once("HTML/Template/IT.php");


// {{{ AuthForm

class AuthFormModule extends PageModule 
{
    // {{{ getContent()

    
    /**
    * getContent()
    *
    */

    function getContent()
    {
        
        trigger_error("ENTER AuthFormModule::getContent()", E_USER_NOTICE);

        $options = &PEAR::getStaticProperty('CONFIG_INI','TEMPLATES'); 
        $global = &PEAR::getStaticProperty('CONFIG_INI','GLOBAL');
    
        $form = new HTML_QuickForm("AuthForm", 'post', rtrim($global['service_url'],'/').'/index.php?cmd=AdminCodeList');

        $statusTpl = new HTML_Template_IT($options["templates_dir"]);
        $statusTpl->loadTemplatefile("status.tpl.xhtml",FALSE,FALSE);

        $form->setDefaults(array('username' => ( isset($_GET['username']) ? $_GET['username'] : null ) ));

        $status = '';
        if (!empty($_GET['status']) && $_GET['status'] == AUTH_EXPIRED) {
            $status = _('Sesja wygasła. Proszę zalogować się ponownie!');
        } else if (!empty($_GET['status']) && $_GET['status'] == AUTH_IDLED) {
            $status = _('Zbyt długi czas bezczynności.Proszę zalogować się ponownie!');
        } else if (!empty ($_GET['status']) && $_GET['status'] == AUTH_WRONG_LOGIN) {
            $status = _('Błędny login lub hasło!');
        } else if (!empty ($_GET['status']) && $_GET['status'] == AUTH_SECURITY_BREACH) {
            $status = _('Wykryto problem z bezpiczeństwem');
        } else {
            $status = _('Podaj login i hasło!');
        }
        $statusTpl->setVariable("STATUS",$status);

        $form->addElement('text','username',_('Login:'));
        $form->addElement('password','password',_('Hasło:'));
        $form->addElement('submit','Login','Login');
        $form->addElement('link','reqister',null,rtrim($global['service_url'],'/').'/?cmd=AuthRegister',_('Nowy użytkownik'));

        $renderer =& new HTML_QuickForm_Renderer_Default($options);
        $renderer -> setFormTemplate(file_get_contents($options["templates_dir"]."form.tpl.xhtml"));
        $renderer -> setElementTemplate(file_get_contents($options["templates_dir"]."formElement.tpl.xhtml"));
        $renderer -> setRequiredNoteTemplate(file_get_contents($options["templates_dir"]."formRequiredNote.tpl.xhtml"));
        $form -> setRequiredNote(null); 
        $form->accept($renderer);

        return $statusTpl->get().$renderer->toHtml().$statusTpl->get();

    }
    
    // }}}

}

// }}} 

?>

